documentation: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#timeseries-offsets
Type | Description | |
---|---|---|
date | Store calendar date (year, month, day) using a Gregorian Calendar | |
datetime | Store both date and time | |
timedelta | Difference between two datetime values |
documentation: http://pandas.pydata.org/pandas-docs/stable/api.html#top-level-dealing-with-datetimelike
to_datetime(*args, **kwargs) | Convert argument to datetime. | |
---|---|---|
to_timedelta(*args, **kwargs) | Convert argument to timedelta | |
date_range([start, end, periods, freq, tz, ...]) | Return a fixed frequency datetime index, with day (calendar) as the default | |
bdate_range([start, end, periods, freq, tz, ...]) | Return a fixed frequency datetime index, with business day as the default | |
period_range([start, end, periods, freq, name]) | Return a fixed frequency datetime index, with day (calendar) as the default | |
timedelta_range([start, end, periods, freq, ...]) | Return a fixed frequency timedelta index, with day as the default | |
infer_freq(index[, warn]) | Infer the most likely frequency given the input index. |
In [3]:
import pandas as pd
import numpy as np
from datetime import datetime
In [4]:
now = datetime.now()
now
Out[4]:
In [5]:
now.year, now.month, now.day
Out[5]:
In [6]:
delta = now - datetime(2001, 1, 1)
delta
Out[6]:
In [7]:
delta.days
Out[7]:
In [8]:
pd.Timedelta('4 days 7 hours')
Out[8]:
In [9]:
# note: these MUST be specified as keyword arguments
pd.Timedelta(days=1, seconds=1)
Out[9]:
In [10]:
pd.Timedelta(1, unit='d')
Out[10]:
In [11]:
us_memorial_day = datetime(2016, 5, 30)
print(us_memorial_day)
us_labor_day = datetime(2016, 9, 5)
print(us_labor_day)
us_summer_time = us_labor_day - us_memorial_day
print(us_summer_time)
type(us_summer_time)
Out[11]:
In [12]:
us_summer_time_range = pd.date_range(us_memorial_day, periods=us_summer_time.days, freq='D')
In [13]:
us_summer_time_time_series = pd.Series(np.random.randn(us_summer_time.days), index=us_summer_time_range)
us_summer_time_time_series.tail()
Out[13]:
In [ ]: